<?php
require_once 'PHPUnit/Framework.php';

require_once(dirname(__FILE__).'/../../../models/feed/UCModFeed.php');
require_once(dirname(__FILE__).'/../../../libraries/UCLibLogger.php');  
/**
@assert (...) == X    assertEquals(X, method(...))
@assert (...) != X    assertNotEquals(X, method(...))
@assert (...) === X    assertSame(X, method(...))
@assert (...) !== X    assertNotSame(X, method(...))
@assert (...) > X    assertGreaterThan(X, method(...))
@assert (...) >= X    assertGreaterThanOrEqual(X, method(...))
@assert (...) < X    assertLessThan(X, method(...))
@assert (...) <= X    assertLessThanOrEqual(X, method(...))
@assert (...) throws X    @expectedException X
*/
class UCModFeedTest extends PHPUnit_Framework_TestCase {

    private $_bmod;
	private $_uid;
    
    protected function setUp()
    {
        UCLibLogger::attach(new StdoutLogOb());
		$this->_uid = $this->providerUserid();
        $this->_bmod = new UCModFeed($this->_uid);
    }

    protected function tearDown()
    {
    }
    
    /**
    * @dataProvider providerUserid
    * 
    */
    function test_addOneFeed()
    {
		$ar_feed =	array(	'activityType'		=>	1002011,
							'objectId'			=>	333333,
							'medalId'			=>	4,
							'medalName'			=>	'友爱勋章',
							'medalIcon'			=>	'http://ipic.staticsdo.com/v1/images/medal/m2_fans_1.png',
							'reviewable'		=>	1,
													);
		$ret = $this->_bmod->addOneFeed($ar_feed);
		if(false===$ret)
		{
			$error = $this->_bmod->getErrorMsg();
			$this->assertTrue($ret, 'errno['.$error['no'].'],error:'.$this->_bmod->getLastError());
		}
    }

	function test_addTemplateFeed()
    {
		$ret = $this->_bmod->addTemplateFeed(1,UCConfFeed::FEED_TEMPLATE_GENERAL,array('content'=>'仅仅是个测试而已'));
		if(false===$ret)
		{
			$error = $this->_bmod->getErrorMsg();
			$this->assertTrue($ret, 'errno['.$error['no'].'],error:'.$this->_bmod->getLastError());
		}
	}

	function test_getFeedsInfoByUid()
    {
		$ret = $this->_bmod->getFeedsInfoByUid();
		if(false===$ret)
		{
			$error = $this->_bmod->getErrorMsg();
			$this->assertTrue($ret, 'errno['.$error['no'].'],error:'.$this->_bmod->getLastError());
		}
	}

	function test_getUsersFeeds()
    {
		$ret = $this->_bmod->getUsersFeeds(array($this->_uid));
		if(false===$ret)
		{
			$error = $this->_bmod->getErrorMsg();
			$this->assertTrue($ret, 'errno['.$error['no'].'],error:'.$this->_bmod->getLastError());
		}
	}

	function test_deleteFeed($uid)
    {
		$ar_ret = $this->_bmod->getFeedsInfoByUid();
		if(false===$ar_ret)
		{
			$error = $this->_bmod->getErrorMsg();
			$this->assertTrue($ar_ret, 'errno['.$error['no'].'],error:'.$this->_bmod->getLastError());
		}
		if(!empty($ret))
		{
			$ret = $this->_bmod->deleteFeed($ar_ret[0]['id']);
			if(false===$ret)
			{
				$error = $this->_bmod->getErrorMsg();
				$this->assertTrue($ret, 'errno['.$error['no'].'],error:'.$this->_bmod->getLastError());
			}
		}
	}                          
    
	function providerUserid($num)
    {
		$ar_user = array(683831455,1244008966,1216006786,5864186);
        return $ar_param[array_rand($ar_user,1)];
    }
}


?>